package com.longrise.android.widget.lviewpage;

import android.annotation.SuppressLint;
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.support.v4.view.PagerAdapter;
import android.support.v4.view.ViewPager.OnPageChangeListener;
import android.text.TextPaint;
import android.util.AttributeSet;
import android.view.Gravity;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.TranslateAnimation;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.longrise.LEAP.Base.IO.Beans.beancontext.BeanContext;

import com.longrise.android.widget.lviewpage.JazzyViewPager.TransitionEffect;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.RunnableFuture;

import static android.R.attr.text;
import static com.longrise.android.widget.lviewpage.JazzyViewPager.TAG;

public class LViewPager extends LinearLayout implements OnPageChangeListener {

    /**
     * 当前的View
     */
    private LinearLayout mainLayout = null;
    /**
     * 头部布局
     */
    private LinearLayout heartLayout = null;
    /**
     * 头部按钮布局
     */
    private LinearLayout btnLayout = null;
    /**
     * 滑动下划线
     */
    private TextView text_line = null;
    /**
     * 中间布局
     */
    private JazzyViewPager jazzyViewPager = null;
    /**
     * 底部布局
     */
    private LinearLayout footerLayout = null;

    private Context context = null;

    /**
     * 是否显示头部的标记值,设置为false就显示底部,默认显示头部
     */
    private boolean showHeart = true;
    /**
     * 属性类，包含了按钮的属性设置
     */
    private List<SwitchBtnParam> switchBtnList = null;
    /**
     * 移动下划线的宽度
     */
    private int width = 0;

    /**
     * LFView对象数组
     */
    private FragmentView[] fragmentLFViews = null;
    /**
     * 当前页面的下标值
     */
    private int currentPage = 0;
    /**
     * 下一页的下标值
     */
    private int nextPage = -1;
    /**
     * 每项Item的UI对象集合
     */
    private List<ItemChildView> itemChildViews = null;
    /**
     * 移动下划线的高度
     */
    private int moveLineHeght = 3;
    /**
     * 移动下划线的颜色
     */
    private int moveLineColor = Color.parseColor("#0000FF");
    /**
     * 设置背景
     */
    private int bgColor = Color.parseColor("#FFFFFF");  //77000000
    /**
     * 是否被创建过标示符
     */
    private boolean isCreate[] = null;
    /**
     * 当前级别
     */
    private int level = -1;

    /**
     * 是否隐藏头部布局
     */
    private boolean isShowTitleLayout = true;

    /**
     * 滑动监听接口
     */
    private OnCurrentViewPagerSelectedListener currentViewPagerSelectedListener;

    public LViewPager(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        this.setWillNotDraw(false);
        this.context = context;

        //初始化集合
        if (null == switchBtnList) {
            switchBtnList = new ArrayList<SwitchBtnParam>();
        } else {
            switchBtnList.clear();
        }
        init();
    }

    @Override
    public void dispatchWindowFocusChanged(boolean hasFocus) {
        super.dispatchWindowFocusChanged(hasFocus);
    }

    public LViewPager(Context context, AttributeSet attrs) {
        super(context, attrs);
        this.setWillNotDraw(false);
        this.context = context;

        //初始化集合
        if (null == switchBtnList) {
            switchBtnList = new ArrayList<SwitchBtnParam>();
        } else {
            switchBtnList.clear();
        }
        init();
    }

    public LViewPager(Context c) {
        super(c);
        this.setWillNotDraw(false);
        this.context = c;

        //初始化集合
        if (null == switchBtnList) {
            switchBtnList = new ArrayList<SwitchBtnParam>();
        } else {
            switchBtnList.clear();
        }
        init();
    }

    public int getCurrentPage() {
        return currentPage;
    }

    //---------------------------get()/set()-------------------------
    public List<SwitchBtnParam> getSwitchBtnList() {
        return switchBtnList;
    }

    public JazzyViewPager getJazzyViewPager() {
        return jazzyViewPager;
    }

    public void setShowTitleLayout(boolean isShowTitleLayout) {
        this.isShowTitleLayout = isShowTitleLayout;
    }

    public void setLevel(int level) {
        this.level = level;
    }

    public void setCurrentViewPagerSelectedListener(OnCurrentViewPagerSelectedListener currentViewPagerSelectedListener) {
        this.currentViewPagerSelectedListener = currentViewPagerSelectedListener;
    }

    public int getBgColor() {
        return bgColor;
    }

    public void setBgColor(int bgColor) {
        this.bgColor = bgColor;
    }

    public int getMoveLineColor() {
        return moveLineColor;
    }

    public void setMoveLineColor(int moveLineColor) {
        this.moveLineColor = moveLineColor;
    }

    public int getMoveLineHeght() {
        return moveLineHeght;
    }

    public void setMoveLineHeght(int moveLineHeght) {
        this.moveLineHeght = moveLineHeght;
    }

    public void setShowHeart(boolean showHeart) {
        this.showHeart = showHeart;
    }
    //---------------------------------------------------------------

    /**
     * 添加SwitchBtnParam对象到集合中
     *
     * @param btnParam
     */
    public void addSwitchBtn(SwitchBtnParam btnParam) {
        if (null != switchBtnList) {
            switchBtnList.add(btnParam);
        }
    }

    public void init() {
        if (null == itemChildViews) {
            itemChildViews = new ArrayList<ItemChildView>();
        } else {
            itemChildViews.clear();
        }

        // ---------------------整体布局--------------------
        mainLayout = new LinearLayout(context);
        // 设置排列模式
        mainLayout.setOrientation(LinearLayout.VERTICAL);
        this.addView(mainLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT));
    }

    /**
     * 初始化UI
     */
    public void createView() {
        fragmentLFViews = null;
        //初始化UI
        initView();
    }

    /**
     * 初始化UI
     */
    private void initView() {
        if (null == this.context) {
            return;
        }

        //--------------------头布局--------------------
        if (showHeart) {
            heartLayout = new LinearLayout(context);
            heartLayout.setBackgroundColor(bgColor);
            //设置排列模式
            heartLayout.setOrientation(LinearLayout.VERTICAL);
            //添加到主布局中
            if (null != mainLayout) {
                mainLayout.addView(heartLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            }

            //添加按钮布局
            btnLayout = new LinearLayout(context);
            if (null != heartLayout) {
                heartLayout.addView(btnLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            }
            if (isShowTitleLayout == false) {
                heartLayout.setVisibility(View.GONE);
            } else {
                heartLayout.setVisibility(View.VISIBLE);
            }

            //滑动的线布局
            RelativeLayout lineLayout = new RelativeLayout(context);
            if (null != heartLayout) {
                LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
                lp.setMargins(0, LWFlowUtil.dip2px(context, 0), 0, 0);
                heartLayout.addView(lineLayout, lp);
                lp = null;
            }

            //添加移动横线
            text_line = new TextView(context);
            text_line.setBackgroundColor(moveLineColor);

            if (null != lineLayout) {
                lineLayout.addView(text_line);
            }

            //添加横线
//			TextView textView = new TextView(context);
//			textView.setBackgroundColor(moveLineColor);
//			if(null != lineLayout)
//			{
//				RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.MATCH_PARENT,
//						LWFlowUtil.dip2px(context, 1));
//				//设置textView位于text_line的下方
//				lp.addRule(RelativeLayout.BELOW, 123456789);
////				lineLayout.addView(textView, lp);
//				lp = null;
//			}
//			textView = null;

        }

        //--------------------中间布局--------------------
        jazzyViewPager = new JazzyViewPager(context);
        //设置适配器
        jazzyViewPager.setAdapter(new MainAdapter());
        //设置外边距
        jazzyViewPager.setPageMargin(30);
        //设置过度效果(注意：设置过度其他的滑动效果时必须重新初始化jazzyViewPager对象)
        jazzyViewPager.setTransitionEffect(TransitionEffect.Standard);
        //设置滑动监听
        jazzyViewPager.setOnPageChangeListener(this);
        //添加到主布局中
        if (null != mainLayout) {
            LayoutParams lp = new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT);
            lp.weight = 1;
            mainLayout.addView(jazzyViewPager, lp);
            lp = null;
        }

        //--------------------底部布局--------------------
        if (!showHeart) {
            footerLayout = new LinearLayout(context);
            footerLayout.setBackgroundColor(bgColor);
            //设置排列模式
            footerLayout.setOrientation(LinearLayout.HORIZONTAL);
            //添加到主布局中
            if (null != mainLayout) {
                mainLayout.addView(footerLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            }

            //添加按钮布局
            btnLayout = new LinearLayout(context);
            if (null != footerLayout) {
                footerLayout.addView(btnLayout, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
            }
        }

        if (null != switchBtnList && switchBtnList.size() > 0) {
            fragmentLFViews = new FragmentView[switchBtnList.size()];
            isCreate = new boolean[switchBtnList.size()];
            for (int i = 0; i < fragmentLFViews.length; i++) {
                fragmentLFViews[i] = switchBtnList.get(i).getFragmentView();
                isCreate[i] = false;
            }
        }

        //--------------------------------------------------------
    }

	/*public FragmentView getLFViewByPosition(int position)
    {
		if(position < 0 || switchBtnList.size() < position)
		{
			return null;
		}
		FragmentView lfView = null;
		SwitchBtnParam btnParam = switchBtnList.get(position);
		if(null != btnParam)
		{
			String path = btnParam.getPaht();
			if(null != path && !"".equals(path))
			{
				Class<?> c = null;
				@SuppressWarnings("rawtypes")
				Constructor constructor = null;
				try 
				{
					 c = Class.forName(path);
					 if(null != c)
					 {
						 constructor = c.getConstructor(Context.class);
					 }
					 if(null != constructor)
					 {
						 lfView = (FragmentView) constructor.newInstance(this.context);
						 if(level != -1)
						 {
							 lfView.setLevel(level);
						 }
					 }
				} 
				catch (Exception e) 
				{
					e.printStackTrace();
				}
			}
		}
		
		return lfView;
	}*/

    private String mBtnLayoutBackColor = "#FFFFFF";  //F3F2F2

    public void setBtnLayoutBackColor(String colorString) {
        this.mBtnLayoutBackColor = colorString;
    }

    private int mBtnLayoutHeight = 0;

    public void setBtnLayoutHeight(int px) {
        this.mBtnLayoutHeight = px;

    }


    /**
     * 添加每一个按钮
     */
    private void addSwitchBtn(SwitchBtnParam switchBtnParam, int i) {
        if (null == switchBtnParam) {
            return;
        }

        ItemChildView childView = new ItemChildView();
        int imgToTitle = switchBtnParam.getImgToTitle();

        //Item项布局
        LinearLayout itemView = new LinearLayout(context);
        itemView.setGravity(Gravity.CENTER);
        //设置线性布局的排列方式
        if (imgToTitle == Gravity.TOP || imgToTitle == Gravity.BOTTOM) {
            itemView.setOrientation(LinearLayout.VERTICAL);
        } else if (imgToTitle == Gravity.LEFT || imgToTitle == Gravity.RIGHT) {
            itemView.setOrientation(LinearLayout.HORIZONTAL);
        }

        //添加图片
        TextView img = null;
        if (switchBtnParam.getNormalImg() > 0 && switchBtnParam.getSelectedImg() > 0) {
            img = new TextView(context);

            if (i == 0) {
                img.setBackgroundResource(switchBtnParam.getSelectedImg());
            } else {
                img.setBackgroundResource(switchBtnParam.getNormalImg());
            }
            childView.setImageView(img);
        }


        // 内容
        TextView titleView = null;
        if (null != switchBtnParam.getTitle() && !"".equals(switchBtnParam.getTitle())) {
            titleView = new TextView(context);
            //设置内边距
            //设置内边距
            titleView.setPadding(switchBtnParam.getTitlePaddingLeft() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getTitlePaddingLeft()) : 0, switchBtnParam.getTitlePaddingTop() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getTitlePaddingTop()) : 0, switchBtnParam.getTitlePaddingRight() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getTitlePaddingRight()) : 0, switchBtnParam.getTitlePaddingBottom() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getTitlePaddingBottom()) : 0);
            titleView.setText(switchBtnParam.getTitle());
            //titleView.setBackgroundColor(Color.parseColor("#00000000"));
            //titleView.setTextSize(LWFlowUtil.dip2px(context,switchBtnParam.getTitleSize()));
            titleView.setTextSize(switchBtnParam.getTitleSize());

            //sjz添加 标题是否加粗
            TextPaint tp = titleView.getPaint();
            if(switchBtnParam.getTextBold()){
                tp.setFakeBoldText(true);
            }else{
                tp.setFakeBoldText(false);
            }

            if (i == 0) {
                titleView.setTextColor(switchBtnParam.getSelectedTitleColor());
            } else {
                titleView.setTextColor(switchBtnParam.getNormalTitleColor());
            }
            childView.setTextView(titleView);
        }

        //根据设置的位置值来排列控件
        switch (imgToTitle) {
            case Gravity.TOP:
            case Gravity.LEFT:
                if (null != img) {
                    LayoutParams lp = new LayoutParams(switchBtnParam.getImgWidth() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgWidth()) : LayoutParams.WRAP_CONTENT, switchBtnParam.getImgHeight() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgHeight()) : LayoutParams.WRAP_CONTENT);
                    //设置内边距
                    lp.setMargins(switchBtnParam.getImgMarginLeft() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginLeft()) : 0, switchBtnParam.getImgMarginTop() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginTop()) : 0, switchBtnParam.getImgMarginRight() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginRight()) : 0, switchBtnParam.getImgMarginBottom() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginBottom()) : 0);
                    itemView.addView(img, lp);
                    lp = null;
                }
                if (null != titleView) {
                    itemView.addView(titleView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                }
                break;

            case Gravity.RIGHT:
            case Gravity.BOTTOM:
                if (null != titleView) {
                    itemView.addView(titleView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
                }
                if (null != img) {
                    LayoutParams lp = new LayoutParams(switchBtnParam.getImgWidth() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgWidth()) : LayoutParams.WRAP_CONTENT, switchBtnParam.getImgHeight() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgHeight()) : LayoutParams.WRAP_CONTENT);
                    //设置内边距
                    lp.setMargins(switchBtnParam.getImgMarginLeft() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginLeft()) : 0, switchBtnParam.getImgMarginTop() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginTop()) : 0, switchBtnParam.getImgMarginRight() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginRight()) : 0, switchBtnParam.getImgMarginBottom() > 0 ? LWFlowUtil.dip2px(context, switchBtnParam.getImgMarginBottom()) : 0);
                    itemView.addView(img, lp);
                    lp = null;
                }
                break;
        }


        if (null != this.itemChildViews) {
            itemChildViews.add(childView);
        }

        itemView.setTag(i);
        //设置单击监听
        itemView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View view) {
                if (null != view.getTag()) {
                    jazzyViewPager.setCurrentItem((Integer) view.getTag());
                }
            }
        });

        if (btnLayout != null) {
            if (mBtnLayoutHeight == 0) {
                btnLayout.addView(itemView, new LayoutParams(width, LayoutParams.MATCH_PARENT));
            } else {
                btnLayout.addView(itemView, new LayoutParams(width, mBtnLayoutHeight));
            }
            btnLayout.setBackgroundColor(Color.parseColor(mBtnLayoutBackColor));
        }
    }

    /**
     * 设置被选中的Item
     * <p>
     * integer
     * 新的Item的下标值
     */
    public void setSelectedItem(Integer integer) {

        if (null == integer) {
            return;
        }

        //设置旧的Item的UI
        setUI(currentPage, false);

        //设置新的Item的UI
        setUI(integer, true);
    }

    /**
     * 根据标识值设置指定Item的UI
     *
     * @param i
     */
    public void setUI(int i, boolean selected) {
        if (null == this.itemChildViews) {
            return;
        }

        if (null == this.switchBtnList) {
            return;
        }

        if (this.switchBtnList.size() > i && switchBtnList.get(i) != null) {
            if (this.itemChildViews.size() > i) {
                ItemChildView childView = this.itemChildViews.get(i);
                if (null != childView) {
                    // 设置图片
                    if (childView.getImageView() != null) {
                        if (selected) {
                            childView.getImageView().setBackgroundResource(switchBtnList.get(i).getSelectedImg());
                        } else {
                            childView.getImageView().setBackgroundResource(switchBtnList.get(i).getNormalImg());
                        }

                    }
                    // 设置字体颜色
                    if (childView.getTextView() != null) {
                        if (selected) {
                            childView.getTextView().setTextColor(switchBtnList.get(i).getSelectedTitleColor());
                        } else {
                            childView.getTextView().setTextColor(switchBtnList.get(i).getNormalTitleColor());
                        }
                    }
                }
            }
        }
    }

    /**
     * 刷新方法，主要是刷新当前所在页的数据
     */
    public void refresh() {
        /*if(currentPage >= 0 && currentPage < this.fragmentLFViews.length)
        {
			if(null != this.fragmentLFViews[currentPage])
			{
				this.fragmentLFViews[currentPage].refresh();
			}
		}*/
        if (null != jazzyViewPager) {
            jazzyViewPager.setCurrentItem(0);
        }
    }

    /**
     * 设置当前的Item值
     *
     * @param integer
     */
    protected void setViewPageCurrentItem(Integer integer) {
        if (null == integer) {
            return;
        }
        if (null != jazzyViewPager) {
            jazzyViewPager.setCurrentItem(integer);
        }
    }

    public void OnDestroy() {
        if (null != fragmentLFViews) {
            for (int i = 0; i < fragmentLFViews.length; i++) {
                if (null != fragmentLFViews[i]) {
                    fragmentLFViews[i].onDestroyView();
                    fragmentLFViews[i].onStop();
                    fragmentLFViews[i].OnDestroy();
                }
            }
        }
        fragmentLFViews = null;

        mainLayout = null;
        heartLayout = null;
        btnLayout = null;
        text_line = null;
        jazzyViewPager = null;
        footerLayout = null;
        context = null;
        showHeart = true;
        switchBtnList = null;
        itemChildViews = null;
        currentViewPagerSelectedListener = null;
    }


    //-----------------------Item滑动回调方法------------------------

    /**
     * 滑动时页面变化的下标值
     * 有三种状态（0，1，2）。
     * arg0 ==1的时辰默示正在滑动，
     * arg0==2的时辰默示滑动完毕了，
     * arg0==0的时辰默示什么都没做。
     * 当页面开始滑动的时候，三种状态的变化顺序为（1，2，0）
     */
    @Override
    public void onPageScrollStateChanged(int i) {
        if (null != this.currentViewPagerSelectedListener) {
            this.currentViewPagerSelectedListener.onViewPageScrollStateChanged(i);
        }
    }

    /**
     * 当页面在滑动的时候会调用此方法，在滑动被停止之前，此方法回一直得到
     * 调用。其中三个参数的含义分别为：
     * arg0 :当前页面，及你点击滑动的页面
     * arg1:当前页面偏移的百分比
     * arg2:当前页面偏移的像素位置
     */
    @Override
    public void onPageScrolled(int i, float f, int j) {
        if (null != this.currentViewPagerSelectedListener) {
            this.currentViewPagerSelectedListener.onViewPageScrolled(i, f, j);
        }
    }

    /**
     * 此方法是页面跳转完后得到调用，arg0是你当前跳转到的页面的Position（位置编号）。
     */
    @Override
    public void onPageSelected(final int i) {
        nextPage = i;
        if (null != currentViewPagerSelectedListener) {
            currentViewPagerSelectedListener.onViewPageSelected(i);
        }
        if (showHeart) {
            if (null != text_line) {
//                Animation animation = null;
//                // 平移动画类,参数：x的起始位置/x的终止位置/y的起始位置/y的终止位置
//                animation = new TranslateAnimation(width * currentPage, width * nextPage, 0, 0);
//                if (animation != null) {
//                    // 设置动画的播放时间
//                    animation.setDuration(100);
//                    // 设置播放完是否回到原处,true表示不会到原处
//                    animation.setFillAfter(true);
//                    text_line.startAnimation(animation);
//                    animation = null;
//                }
                //sjz修改
                RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) text_line.getLayoutParams();
                layoutParams.leftMargin = width * i;
                text_line.setLayoutParams(layoutParams);
            }
        }
        //刷新页面的数据
        /*if(i >= 0 && i < this.fragmentLFViews.length)
		{
			if(null != this.fragmentLFViews[i])
			{
				this.fragmentLFViews[i].refresh();
			}
		}*/
        setSelectedItem(i);
        currentPage = nextPage;
    }
    //-----------------------------------------------------------


    /**
     * 适配器类
     */
    private class MainAdapter extends PagerAdapter {
        /***
         * 实例化Item
         */
        @Override
        public Object instantiateItem(ViewGroup container, final int position) {
            View view_ = null;
            if (null != isCreate) {
                if (!isCreate[position]) {
                    fragmentLFViews[position].onCreate();
                    fragmentLFViews[position].onStart();
                    isCreate[position] = true;
                }

                view_ = fragmentLFViews[position].onCreateView(context);
                container.addView(view_, LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
                //为对象设置下标值
                jazzyViewPager.setObjectForPosition(view_, position);
            }
			
			/*LFView lfView = getLFViewByPosition(position);
			if(null != lfView)
			{
				fragmentLFViews[position] = lfView;
				lfView.init();
				container.addView(lfView.getView(), LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT);
				//为对象设置下标值
				jazzyViewPager.setObjectForPosition(lfView.getView(), position);
				return lfView.getView();
			}*/
            return view_;
        }

        /**
         * 销毁Item方法
         */
        @Override
        public void destroyItem(ViewGroup container, int position, Object obj) {
            container.removeView(jazzyViewPager.findViewFromObject(position));
            if (null != fragmentLFViews && null != fragmentLFViews[position]) {
                fragmentLFViews[position].onDestroyView();
            }
        }

        /**
         * 总数据
         */
        @Override
        public int getCount() {
            return switchBtnList.size();
        }

        @Override
        public boolean isViewFromObject(View view, Object obj) {
            if (view instanceof OutlineContainer) {
                return ((OutlineContainer) view).getChildAt(0) == obj;
            } else {
                return view == obj;
            }
        }
    }

    @SuppressLint("DrawAllocation")
    @Override
    protected void onDraw(Canvas canvas) {
        if (width <= 0) {
            //该控件的宽度/标题个数
            width = this.getWidth() / this.switchBtnList.size();
            if (showHeart) {
                RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(width, LWFlowUtil.dip2px(context, moveLineHeght > 0 ? moveLineHeght : 3));
                this.text_line.setLayoutParams(lp);
            }

            // 添加头部按钮
            if (null != switchBtnList && switchBtnList.size() > 0) {
                for (int i = 0; i < switchBtnList.size(); i++) {
                    addSwitchBtn(switchBtnList.get(i), i);
                }
            }
        }
        super.onDraw(canvas);

    }

    /**
     * 设置当前选中的页面
     *
     * @param index
     */
    public void setViewPagerCurrentItem(int index) {
        if (index < 0) {
            return;
        }
        if (null != fragmentLFViews && fragmentLFViews.length > index && null != jazzyViewPager) {
            jazzyViewPager.setCurrentItem(index);
        }
    }
}
